/*
When a shadow falls across your world,
and your enemy wants nothing but your annihilation.
Where will you find your allies,
in a desperate struggle for survival.
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
int t,n,pos[1000005],dp[2005][2005],a[100005];
void cmax(int &x,int y){
    x=max(x,y);
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&t);
    while(t--){
        memset(dp,0,sizeof(dp));
        scanf("%lld",&n);
        for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
        for(int i=1;i<=n;i++){
            for(int j=0;j<=i;j++){
                cmax(dp[i+1][j],dp[i][j]+(a[i]==a[i+1])*a[i]);
                cmax(dp[i+1][i],dp[i][j]+(a[j]==a[i+1])*a[j]);
            }
        }
        int ans=0;
        for(int i=0;i<n;i++)cmax(ans,dp[n][i]);
        cout<<ans<<"\n";
    }
    return 0;
}